require "test/unit"
require "str_matching/rabin_karp.rb"
require "testing_utils.rb"

class TestRabinKarp < Test::Unit::TestCase
  def test_find()
    source = "abcdefbCdEfGhijklm"

    pattern = "bCdEfGh"

    assert_rabin_karp_match(source, pattern)

    pattern = ""
    
    assert_rabin_karp_match(source, pattern)
    
    pattern = "012345"
    
    assert_rabin_karp_match(source, pattern)
  end
  
  private
  
  def assert_rabin_karp_match(source, pattern)
    exp_match = source.index(pattern)
    act_match = RabinKarp.match(source, pattern)
    
    assert_equal exp_match, act_match
  end
end